package cn.iotab.iotkit.transport.api.access.model.custom.event;

import cn.iotab.iotkit.transport.api.access.model.custom.ProtocolConstant;
import cn.iotab.iotkit.transport.api.access.model.message.CommonDeviceMessage;
import cn.iotab.iotkit.transport.api.access.model.message.OriginMessage;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * 设备 -> 平台
 */
@Getter
@Setter
public class EventMessage extends CommonDeviceMessage {

    private String eventId;


    @Override
    public void fromOriginMessage(String productKey, String deviceId, OriginMessage message) {
        super.fromOriginMessage(productKey, deviceId, message);
        this.eventId = StringUtils.substring(getOriginType(), ProtocolConstant.EVENT_PREFIX.length());
    }

    @Override
    public OriginMessage toOriginMessage() {
        String originType = ProtocolConstant.EVENT_PREFIX + eventId;
        setOriginType(originType);
        return super.toOriginMessage();
    }
}
